package cn.aylog.controller;

import cn.aylog.pojo.Money;
import cn.aylog.service.IMoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/money")
public class MoneyController {

    @Autowired
    private IMoneyService service;

    @RequestMapping("/{id}")
    public String index(@PathVariable Integer id) {
        System.out.println(service.getById(id));
        return "index";
    }

    @RequestMapping("/trans/{from}/{to}/{money}")
    public String trans(@PathVariable("from") Integer from, @PathVariable Integer to, @PathVariable Integer money) {
        Money fromM = service.getById(from);
        Money toM = service.getById(to);
        service.transMoney(fromM, toM, money);
        return "index";
    }

    @RequestMapping("/trans-e/{from}/{to}/{money}")
    public String transE(@PathVariable("from") Integer from, @PathVariable Integer to, @PathVariable Integer money) {
        Money fromM = service.getById(from);
        Money toM = service.getById(to);
        service.transMoneyE(fromM, toM, money);
        return "index";
    }

    @RequestMapping("/reset")
    public String reset() {
        service.reset();
        return "index";
    }

    @RequestMapping("/test/reset")
    public String reset2() {
        service.reset();
        return "index";
    }
}

